﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using Model;
using BLL;
namespace UI
{
    public partial class 修改操作 : Form
    {
        public 修改操作()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            new 登录界面().Show();
            //关闭本窗体
            this.Close();
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //判断是否隐藏
            if (textBox1.Enabled ==false)
            {
                string pwd = textBox2.Text;
                if (pwd == "")
                {
                    MessageBox.Show("请填写完整信息");
                    return;
                }
                Admins.UserPwd = pwd;
                int count = 修改操作BLL.XuigaiPwd();
                if (count > 0)
                {
                    MessageBox.Show("修改成功");
                    //实例化XmlDocument
                    XmlDocument docu = new XmlDocument();
                    //加载xml
                    docu.Load("../../XMLFile1.xml");
                    //获取根节点
                    XmlNode node = docu.DocumentElement;
                    foreach (XmlNode item in node.ChildNodes)
                    {
                        //条件成立就执行
                        if (item["Uid"].InnerText == textBox1.Text)
                        {
                            item["Pwd"].InnerText = textBox2.Text;
                            //保存
                            docu.Save("../../XMLFile1.xml");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("修改失败");
                }
                return;
            }
            //获取数据
            string uid = textBox1.Text;
            string Name = textBox2.Text;
            //非空判断
            if (uid == "" || Name =="")
            {
                MessageBox.Show("请填写完整信息");
                return;
            }
            //传值
            Admins.UserID = int.Parse(uid);
            Admins.UserCompellation = Name;
            //执行操作
            object o = 修改操作BLL.Xuigai();
            if (Convert.ToInt32(o) >0)
            {
                //隐藏
                label1.Enabled = false;
                textBox1.Enabled = false;
                //修改label2值
                label2.Text = "密码";
                textBox2.Text = "";

            }
            else
            {
                MessageBox.Show("请输入正确的信息");
            }
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar !=8)
            {
                if (!(char.IsDigit(e.KeyChar)))
                {
                    MessageBox.Show("请填写数字");
                    e.Handled = true;
                }
            }
        }
    }
}
